package com.yxw.yx_hotel.controller;

import com.yxw.yx_hotel.dto.AddRoomDto;
import com.yxw.yx_hotel.dto.QueryRoomDto;
import com.yxw.yx_hotel.dto.QueryRoomManageDto;
import com.yxw.yx_hotel.dto.QueryRoomStatisticsDto;
import com.yxw.yx_hotel.service.RoomService;
import com.yxw.yx_hotel.vo.RoomBedVo;
import com.yxw.yx_hotel.vo.RoomManageVo;
import com.yxw.yx_hotel.vo.RoomStatisticsVo;
import com.yxw.yx_hotel.vo.RoomVo;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.alibaba.fastjson.JSONObject;
import com.yxw.yx_hotel.entity.YxRoomEntity;
import java.util.List;

/**
 *  宿舍管理
 * @author liuxin
 * @date 2024.01.17
 */
@RestController
@Api(value = "宿舍管理", tags = "宿舍管理")
@Slf4j
@RequestMapping("/api/room")
public class RoomController {

    @Autowired
    private RoomService  roomService;
    
    @ApiOperation(value = "获取一个新宿舍的Id")
    @GetMapping("/getNewRoomId")
    public BaseResult getNewRoomId()  {
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("roomId", IdWorker.getId());
        return BaseResult.doSuccess(oJSONObject,"获取成功");
    }
    
    @ApiOperation(value = "新增宿舍")
    @PostMapping("/addRoom")
    public BaseResult addRoom(@Validated @RequestBody  AddRoomDto dto)  {
        roomService.addRoom(dto);
        return BaseResult.doSuccess(null,"新增成功");
    }

    @ApiOperation(value = "删除宿舍")
    @PostMapping("/deleteRoom")
    public BaseResult deleteRoom(@RequestParam Long roomId)  {
        roomService.deleteRoom(roomId);
        return BaseResult.doSuccess(null,"删除成功");
    }

    @ApiOperation(value = "修改宿舍")
    @PostMapping("/updateRoom")
    public BaseResult updateRoom(@Validated @RequestBody  AddRoomDto dto)  {
        roomService.updateRoom(dto);
        return BaseResult.doSuccess(null,"修改成功");
    }

    @ApiOperation(value = "查询宿舍列表分页")
    @PostMapping("/pageRoomList")
    public BaseResult<PageVO<YxRoomEntity>> pageRoomList(@RequestBody  QueryRoomDto dto)  {
        PageVO<YxRoomEntity> pageVo=roomService.pageRoomList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }
    @ApiOperation(value = "查询宿舍列表分页")
    @PostMapping("/getRoomList")
    public BaseResult<List<YxRoomEntity>> getRoomList(@RequestBody  QueryRoomDto dto)  {
        List<YxRoomEntity> listVo=roomService.getRoomList(dto);
        return BaseResult.doSuccess(listVo,"查询成功");
    }    
    @ApiOperation(value = "查询宿舍详情")
    @PostMapping("/getRoomById")
    public BaseResult<RoomVo> getRoomById(@RequestParam Long roomId)  {
        RoomVo vo =roomService.getRoomById(roomId);
        return BaseResult.doSuccess(vo,"查询成功");
    }

    @ApiOperation(value = "房源统计列表查询")
    @PostMapping("/pageRoomStatisticsList")
    public BaseResult<PageVO<RoomStatisticsVo>> pageRoomStatisticsList(@RequestBody QueryRoomStatisticsDto dto)  {
        PageVO<RoomStatisticsVo> pageVo =roomService.pageRoomStatisticsList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }

    @ApiOperation(value = "房态管理-列表查询")
    @PostMapping("/pageRoomManageList")
    public BaseResult<PageVO<RoomManageVo>> pageRoomManageList(@RequestBody QueryRoomManageDto dto)  {
        PageVO<RoomManageVo> pageVo =roomService.pageRoomManageList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }

    @ApiOperation(value = "根据宿舍ID查询床位列表")
    @PostMapping("/getRoomBedByRoomId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "宿舍ID", required = true),
            @ApiImplicitParam(name = "status", value = "0: 待住  1：已住  空：全部", required = false)
    })
    public BaseResult<List<RoomBedVo>> getRoomBedByRoomId(@RequestParam Long roomId,Integer status)  {
        List<RoomBedVo> voList =roomService.getRoomBedByRoomId(roomId,status);
        return BaseResult.doSuccess(voList,"查询成功");
    }
}
